# -*- coding: utf-8 -*-..,
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp.osv import fields, osv
import csv
import itertools

try:
    from cStringIO import StringIO
except ImportError:
    from StringIO import StringIO

# ?????
#  only can be saving, afterchoosing "Active..."  => ???? 
#
# 
class crea8s_training3_class(osv.osv):
    _inherit = "crea8s.training1.demo.class"
    _description = 'crea8s_training3_import asdasdasd...'
    _columns = {
        'name_training3': fields.char('Name', size=256),
        'datetime': fields.datetime('Date&Time'),

# 'state': fields.selection([('draft','Draft'),
# ('confirmed','Confirmed')],'State',required=True,readonly=True)
    }
    strFormatTime = '%Y-%m-%d %H:%M:%S %Z'
    def act_helloword333(self, cr, uid, ids, context={}):
       return self.write(cr, uid, ids, {'name': 'Hello word (by crea8s_training3_class)'})
   
    def import_csv_into_training1(self, cr, uid, ids, context={}):
        
        
#         record.file # aaaaaaaa
        csv_iterator = csv.reader(
                                  
            StringIO('D:\Data_IT\openerp\cust-oe\unk-2-import-RES.PARTNER\res.partner-lite.csv'),
                quotechar='"',
                delimiter=',',
            
#             quotechar=str(options['quoting']),
#             delimiter=str(options['separator']),  #dict: {u'headers': True, u'quoting': u'"', u'separator': u',', u'encoding': u'utf-8'}

            
            )
        csv_nonempty = itertools.ifilter(None, csv_iterator)
        # TODO: guess encoding with chardet? Or https://github.com/aadsm/jschardet
#         encoding = options.get('encoding', 'utf-8')
        
        objROWs=  itertools.imap(
            lambda row: [item.decode("utf-8") for item in row],
            csv_nonempty)
        arrPreview = itertools.islice(objROWs, 1)
        print 'import_csv_into_training1: ...' + str(list(arrPreview) )
    
        return True
        
        
   
   
crea8s_training3_class()





